/**
 * @FileName: PermNode.java
 * @Author
 * @Description:
 * @Date 2015年12月23日 下午4:39:59
 * @CopyRight ZTE Corporation
 */
package cn.hpclub.server.role;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PermissionNode implements Serializable{
    private static Logger        log              = LoggerFactory.getLogger(PermissionNode.class);
    private static final long    serialVersionUID = -3070608660641451315L;
    private int                  id;
    private int                  parentId;
    private int                  level;
    private String               name;
    private boolean              hasLeafNode      = false;
    private boolean              isLeafNode       = false;
    private boolean              selected         = false;
    private List<PermissionNode> subNodes;

    public int getId(){
        return id;
    }

    public void setId(int id){
        this.id = id;
    }

    public String getName(){
        return name;
    }

    public void setName(String name){
        this.name = name;
    }

    public boolean isLeafNode(){
        return isLeafNode;
    }

    public void setLeafNode(boolean isLeafNode){
        this.isLeafNode = isLeafNode;
    }

    public List<PermissionNode> getSubNodes(){
        return subNodes;
    }

    public void addSubNode(PermissionNode node){
        if(subNodes == null){
            subNodes = new ArrayList<PermissionNode>();
        }
        if(node.isLeafNode){
            hasLeafNode = true;
        }
        subNodes.add(node);
    }

    public int getParentId(){
        return parentId;
    }

    public void setParentId(int parentId){
        this.parentId = parentId;
    }

    public void setSubNodes(List<PermissionNode> subNodes){
        this.subNodes = subNodes;
    }

    public boolean isHasLeafNode(){
        return hasLeafNode;
    }

    public void setHasLeafNode(boolean hasLeafNode){
        this.hasLeafNode = hasLeafNode;
    }

    public int getLevel(){
        return level;
    }

    public void setLevel(int level){
        this.level = level;
    }

    public boolean isSelected(){
        return selected;
    }

    public void setSelected(boolean selected){
        this.selected = selected;
    }

    /**
     * @return
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString(){
        return name + "[" + id + ",pId:" + parentId + ",checked:" + selected + ",hasLeafNode:" + hasLeafNode + "]";
    }

    public void printNodes(String prefix){
        log.info(prefix + toString());
        if(subNodes != null){
            for(PermissionNode subNode : subNodes){
                subNode.printNodes(prefix + "--");
            }
        }

    }
}
